#include "vzenith_tools.h"

#include "curl_md5.h"
#include "curl_base64.h"
#include "vzenith_sha1.h"

void calculate_md5(
  char *output,
  const char *input) {
  Curl_md5it((unsigned char*)output, (const unsigned char*)input);
}

CURLcode encode_base64(
  char **output,
  size_t *outsize,
  const char *input,
  size_t insize) {
  return Curl_base64_encode(NULL, input, insize, output, outsize);
}

CURLcode md5_base64(
  char **output,
  size_t *outsize,
  const char *input) {
  char md5[16] = { 0 };
  Curl_md5it((unsigned char*)md5, (const unsigned char*)input);
  return Curl_base64_encode(NULL, md5, 16, output, outsize);
}

CURLcode calculate_signature(
  char **output,
  size_t *outsize,
  const char *key,
  int keylen,
  const char *input,
  size_t insize) {
  size_t len = 20;
  unsigned char sha1[20] = { 0 };
  hmac_sha1(sha1, &len, key, keylen, (const unsigned char*)input, insize);
  return Curl_base64_encode(NULL, (char*)sha1, len, output, outsize);
}
